<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib tagdir="/WEB-INF/tags/" prefix="bt"%>

<div class="span8 offset2">
    <form class="form-horizontal well" method="POST" action="MainServlet?action=trip.save" onsubmit="return checkTrip();">
        <fieldset>
            <legend>Edit trip</legend>
            <div class="hidden">
                <input type="hidden" name="id" value="<c:out value="${trip.getId()}" />">
            </div>
            <div id="routeControlGroup" class="control-group">
                <label class="control-label" for="route">Route:</label>
                <div class="controls">
                    <select class="myinput" id="route" name="route">
                        <c:forEach var="route" items="${routeList}">
                            <c:choose>
                                <c:when test="${!route.toString().equals(trip.getRoute().toString())}">
                                    <option value="${route.getId()}"><c:out value="${route.getRouteName()}" /></option>
                                </c:when>
                                <c:when test="${route.toString().equals(trip.getRoute().toString())}">
                                    <option selected="true" value="${route.getId()}"><c:out value="${route.getRouteName()}" /></option>
                                </c:when>
                            </c:choose>
                        </c:forEach>
                    </select>
                    <span id="routeHelpInline" class="help-inline"></span>
                </div>
            </div>
            <div id="tripStateControlGroup" class="control-group">
                <label class="control-label" for="tripState">Trip state:</label>
                <div class="controls">
                    <select class="myinput" id="tripState" name="tripState">
                        <c:forEach var="tripState" items="${tripStateList}">
                            <c:choose>
                                <c:when test="${tripState != trip.getTripState()}">
                                    <option value="<c:out value="${tripState.toString()}" />"><c:out value="${tripState.toString()}" /></option>
                                </c:when>
                                <c:when test="${tripState == trip.getTripState()}">
                                    <option selected="true" value="<c:out value="${tripState.toString()}" />"><c:out value="${tripState.toString()}" /></option>
                                </c:when>
                            </c:choose>
                        </c:forEach>
                    </select>
                    <span id="tripStateHelpInline" class="help-inline"></span>
                </div>
            </div>
            <div id="tripDateControlGroup" class="control-group">
                <label class="control-label" for="tripDate">Trip date:</label>
                <div class="controls">
                    <input class="myinput" type="text" id="tripDate" name="tripDate" value="<c:out value="${trip.getTripDateString()}" />">
                    <span id="tripDateHelpInline" class="help-inline"></span>
                </div>
            </div>
            <div id="busControlGroup" class="control-group">
                <label class="control-label" for="bus">Bus:</label>
                <div class="controls">
                    <select class="myinput" id="bus" name="bus">
                        <c:forEach var="bus" items="${busList}">
                            <c:choose>
                                <c:when test="${!bus.toString().equals(trip.getBus().toString())}">
                                    <option value="<c:out value="${bus.getId()}" />"><c:out value="${bus.getStateNumber()}" /></option>
                                </c:when>
                                <c:when test="${bus.toString().equals(trip.getBus().toString())}">
                                    <option selected="true" value="<c:out value="${bus.getId()}" />"><c:out value="${bus.getStateNumber()}" /></option>
                                </c:when>
                            </c:choose>
                        </c:forEach>
                    </select>
                    <span id="busHelpInline" class="help-inline"></span>
                </div>
            </div>
            <div id="driverNameControlGroup" class="control-group">
                <label class="control-label" for="driverName">Driver name:</label>
                <div class="controls">
                    <input class="myinput" type="text" id="driverName" name="driverName" value="<c:out value="${trip.getDriverName()}" />">
                    <span id="driverNameHelpInline" class="help-inline"></span>
                </div>
            </div>
            <div id="conductorNameControlGroup" class="control-group">
                <label class="control-label" for="conductorName">Conductor name:</label>
                <div class="controls">
                    <input class="myinput" type="text" id="conductorName" name="conductorName" value="<c:out value="${trip.getConductorName()}" />">
                    <span id="conductorNameHelpInline" class="help-inline"></span>
                </div>
            </div>
            <div class="form-actions">
                <input type="submit" class="btn btn-primary" name="saveButton" value="Save trip data">
                <button class="btn" id="cancelButton" name="cancelButton" data-button-to-click="cancelButtonOutOfForm">Cancel</button>
                <input type="reset" class="btn" name="resetButton" value="Reset">
            </div>
        </fieldset>
    </form>
    <button class="btn" id="cancelButtonOutOfForm" data-link="trip-list" style="display: none; visibility: hidden; height: 0px; width: 0px;">Cancel</button>
</div>
